<?php include $this->templateDir .'common/header.php';?>
<style>
    .roleListMain .layui-unselect span{color: #5FB878;font-weight: bolder} </style>
<body style="padding: 10px;">
<form class="layui-form layui-form-pane">
    <input type="hidden" name="role_id" value="<?php echo $this->res['role_id']?>">
    <div class="layui-form-item" >
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="title" lay-verify="required"  value="<?php echo $this->res['role_name']?>">
        </div>
    </div>

    <div class="layui-form-item" pane="">
        <div class="layui-inline">
            <label class="layui-form-label">权限菜单</label>
            <!-- 循环出所有一级菜单-->
            <?php
            foreach ($this->datas  as $k=>$v) { ?>
                <div class="layui-input-block">
                    <div class="roleList">
                        <div class="roleListMain">
                            <input type="checkbox" name="menu[<?php  echo  $v['mid']?>]" lay-skin="primary" title="<?php echo $v['title']?>" <?php  if(isset($this->res['role_content'] ) && in_array($v['mid'],$this->res['role_content']) ){echo " checked";}else{echo '';} ;?> >
                        </div>
                        <!-- 循环出所有二级菜单-->
                        <div class="roleListSon">
                            <?php if(is_array($v['children'])){ foreach ($v['children'] as $keychild => $vchild) {  ?>
                                <input type="checkbox" name="menu[<?php echo $vchild['mid']?>]" lay-skin="primary" title="|----<?php echo $vchild['title']?>" <?php if(isset($this->res['role_content'] ) && in_array($vchild['mid'],$this->res['role_content']) ){ echo "checked";}else{echo '';}?>>
                            <?php } } ?>
                        </div>
                        <hr>
                    </div>
                </div>
            <?php  } ?>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="graceSubBtn" lay-submit="" lay-filter="*">编辑角色</button>
        </div>
    </div>
</form>
</body>
</html>
<script type="text/javascript">
    layui.use(['form','layer'],function(){
        var form = layui.form;
        $ = layui.jquery;
        layer = layui.layer;

        // 保存
        form.on('submit(*)', function(data){
            // 提交操作
            var saveUrl ='<?php echo PG_SROOT."role/edit/" ;?>'+data.field.role_id ;
            $.post(saveUrl,data.field,function(res){
                if(res.status == "ok"){
                    layer.msg(res.data,{'icon':1});
                    setTimeout(function(){parent.window.location.reload();},1000);
                }else{
                    layer.msg(res.data,{'icon':2});
                }
            },'json');
            return false;
        });
    });
</script>